/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.app.dao;

import com.mysql.jdbc.PreparedStatement;
import edu.app.connection.ConnectionFactory;
import edu.app.persistence.Film;
import edu.app.persistence.Utilisateur;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import edu.app.persistence.Commentaire;

/**
 *
 * @author admin
 */
public class CommentaireDAO {
     protected Connection connection = ConnectionFactory.getInstance().getConnection();

     public String affich_commentaire(Film f){
         
     PreparedStatement ps   =null;
     ResultSet rs = null;
     String var = ""  ;
     String sql="select com from  commentaire where nomfilm=?";
        try {
            ps = (PreparedStatement) connection.prepareStatement(sql);
            ps.setString(1, f.getNom());
          rs =  ps.executeQuery();
         while (rs.next()){

         var = var + rs.getString("com");
         
         }
        } catch (SQLException ex) {
            Logger.getLogger(CommentaireDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    
      return var;
     }

     public void poster_com (Utilisateur u , Film f ,Commentaire c)
    {
      PreparedStatement ps =null;
      ResultSet rs = null;
      String sql="insert into commentaire (login,com,nomfilm) values(?,?,?)";
        try {
            ps = (PreparedStatement) connection.prepareStatement(sql);
            ps.setString(1, u.getLogin());
            ps.setString(2, c.getCom(u.getLogin()));
            ps.setString(3, f.getNom());
            ps.executeUpdate();
            

        } catch (SQLException ex) {
            Logger.getLogger(CommentaireDAO.class.getName()).log(Level.SEVERE, null, ex);
        }

     }

}
